package com.pan.cart;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class CartAnalysisMapper extends Mapper<LongWritable, Text,Text, IntWritable> {
    IntWritable outV;
    Text outK ;

    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, IntWritable>.Context context) throws IOException, InterruptedException {
        String line = value.toString();
        String[] cartItem = line.split(",");
        String goodsId = cartItem[0];
        Integer goodsCount = Integer.valueOf(cartItem[1]);
        outK = new Text();
        outK.set(goodsId);
        outV = new IntWritable();
        outV.set(goodsCount);
        context.write(outK,outV);
    }
}
